import { BasicColumn, FormProps } from '/@/components/Table';
import { getActivityStatesList, getStatesList } from '/@/api/sys/chinaUnionPayorderList';
import { Tag } from 'ant-design-vue';
import { t } from '/@/hooks/web/useI18n';

export function getBasicColumns(): BasicColumn[] {
  return [
    {
      title: '本网中间订单号',
      dataIndex: 'order_id',
      width: 160,
      align: 'left',
    },
    {
      title: '银联订单号',
      dataIndex: 'unionpay_orderid',
      width: 120,
      align: 'left',
    },
    {
      title: '订单状态',
      dataIndex: 'status',
      width: 80,
      align: 'left',
      customRender: ({ text }) => {
        if (text === 0) {
          return <Tag color="green">{() => t('下单未支付')}</Tag>;
        } else if (text === 1) {
          return <Tag color="red">{() => t('下单支付')}</Tag>;
        } else if (text === 2) {
          return <Tag color="blue">{() => t('订单完成')}</Tag>;
        }
      },
    },
    {
      title: '收货人',
      dataIndex: 'contact_name',
      width: 80,
      align: 'left',
    },
    {
      title: '收货人手机号',
      dataIndex: 'mobile',
      width: 120,
      align: 'left',
    },
    {
      title: '省份',
      dataIndex: 'province',
      width: 60,
      align: 'left',
    },
    {
      title: '市',
      dataIndex: 'city',
      width: 60,
      align: 'left',
    },
    {
      title: '区',
      dataIndex: 'county',
      width: 60,
      align: 'left',
    },
    {
      title: '详细地址',
      dataIndex: 'address',
      width: 120,
      align: 'left',
    },
    {
      dataIndex: 'commodity_infs',
      title: '商品编号和商品名称',
      width: 170,
      customRender: ({ record }) => {
        const list = record.commodity_infs;
        return (
          <span>
            {list.map((c) => (
              <div key={c.commodityId}>
                {c.product_no},<a href={c.img_path}>{c.commodity_name}</a>
              </div>
            ))}
          </span>
        );
      },
    },
    {
      title: '订单提交时间',
      dataIndex: 'create_time',
      width: 180,
      align: 'left',
    },
    {
      title: '本网订单号',
      dataIndex: 'benlai_orderid',
      width: 120,
      align: 'left',
    },
    {
      title: '快递公司',
      dataIndex: 'logistics',
      width: 120,
      align: 'left',
    },
    {
      title: '快递单号',
      dataIndex: 'logistics_no',
      width: 120,
      align: 'left',
    },
  ];
}

export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    autoSubmitOnEnter: true,
    schemas: [
      {
        field: 'hdid',
        defaultValue: 1,
        component: 'ApiSelect',
        label: '活动名称',
        colProps: {
          span: 12,
        },
        componentProps: {
          placeholder: '请选择活动,默认银联权益活动',
          api: getActivityStatesList,
          resultField: 'list',
          labelField: 'hd_name',
          valueField: 'hd_id',
        },
      },
      {
        field: 'orderId',
        component: 'Input',
        label: '搜索',
        colProps: {
          span: 12,
        },
        componentProps: {
          placeholder: '请输入订单号，中间订单号，本网单号',
        },
      },
      {
        field: 'status',
        component: 'ApiSelect',
        label: '订单状态',
        colProps: {
          span: 12,
        },
        componentProps: {
          placeholder: '请选择状态',
          api: getStatesList,
          resultField: 'list',
          labelField: 'text',
          valueField: 'value',
        },
      },
      {
        field: 'fieldTime',
        component: 'RangePicker',
        label: '起止日期',
        colProps: {
          span: 8,
        },
      },
    ],
    fieldMapToTime: [['fieldTime', ['beginTime', 'endTime'], 'YYYY-MM-DD']],
  };
}
